/**
 * Created by gemini on 2017/4/20.
 */
myApp.controller('memberlistCtrl',function ($scope,$state,$cookieStore,$uibModal,memberService) {
    $scope.company_id = $cookieStore.get("operator").company_id;

    $scope.pages = {
        maxSize:10,
        pageSize:10,
        currentPage:1,
        totalPages:""
    };

    var commonList = function (company_id,currentPage,pageSize) {
        memberService.memberList(company_id,currentPage,pageSize,function (data) {
            if(!data.errno == 0){
                alert(data.errmsg);
            }else{
                $scope.nums = data.data;
                $scope.members = data.data.data;
                $scope.pages.totalPages = data.data.count;
            }
        });
    };

    //路由传参，member_id
    $scope.edit = function (memberId) {
        $state.go('main.memberDetail', {member_id: memberId});
    };

    //会员列表
    commonList($scope.company_id,$scope.pages.currentPage,$scope.pages.pageSize);

    //分页切换
    $scope.changePages = function (page) {
        commonList($scope.company_id,page,$scope.pages.pageSize);
    };

    //页面跳转
    $scope.jumpToUrl = function (targetUrl) {
        $state.go(targetUrl);
    };

    //模态框
    $scope.openModal = function () {

        var modalInstance = $uibModal.open({
            templateUrl:'views/member/memberEditModal.html',
            controller:'editModalCtrl',
            size:'lg',
            backdrop:true,
            resolve:{
                dataObj:{arr:$scope.arrs}
            }
        });
        modalInstance.result.then(function (selectedItem) {
            $scope.selected = selectedItem;
        });
    };

    /*$scope.openAddModal = function () {

        var modalInstance = $uibModal.open({
            templateUrl:'views/member/memberAddModal.html',
            controller:'editModalCtrl',
            size:'lg',
            backdrop:true,
            resolve:{
                dataObj:{arr:$scope.arrs}
            }
        });
        modalInstance.result.then(function (selectedItem) {
            $scope.selected = selectedItem;
        });
    };*/
});